import React from 'react';
import {injectIntl} from 'react-intl';
import {Button } from 'antd';
import Grid from '../../components/table/grid';
import {sessionManager} from "../../utils/sessionStorage";
import SCModal from '../../components/pickCity/SCModal'
import qs from 'qs';
import axios from 'axios';
class AdjustHis extends React.Component {
    constructor(props) {
        super(props);
        this.common = this.props.intl.messages.common;
        this.columnsPop=[
            {
                title: '开票时间',
                dataIndex: 'invoiceMonth',
                key: 'invoiceMonth',
            },
            {
                title: '发票金额',
                dataIndex: 'invoiceAmount',
                key: 'invoiceAmount',
            },
            {
                title: '税点金额',
                dataIndex: 'invoiceTax',
                key: 'invoiceTax',
            }
        ];
        this.columns = [
            {
                title: '调整时间',
                dataIndex: 'createTime',
                key: 'createTime',
            },
            {
                title: '调整金额（元）',
                dataIndex: 'money',
                key: 'money',
            },
            {
                title: '实际电量（度）',
                dataIndex: 'actualPower',
                key: 'actualPower',
            },
            {
                title: '调整原因',
                key: 'infos',
                render: (text, record) => (
                    <span>
                        {record.isAutogeneration===1&&<a onClick={() => {this.setState({
                            visible:true
                        })}}>发票抵扣</a>}
                        {record.isAutogeneration!==1&&<span>{record.info}</span>}
                    </span>
                )
            },
        ];
        this.state={
            visible:false,
        }
    }

    render(){
        const BillInfo=sessionManager.get('BillInfo');
        const token=(JSON.parse(sessionStorage.getItem("token"))||{}).token;
        let locale=sessionManager.get('locale');
        let exportQs=`&id=${BillInfo.id}&token=${token}&locale=${locale}`;
        return(
            <div>
                <Grid columns={this.columns} params={{id:BillInfo.id}} url="/api/settlement/settled/adjustList"/>
                <SCModal visible={this.state.visible} handleCancel={()=>{this.setState({visible:false})}} title={'发票抵扣'}>
                <a href={`${axios.defaults.baseURL}/api/settlement/adjustInvoiceOrderInfo/export?${exportQs}`}>
                    <Button style={{marginBottom:15}} type={'primary'}>{'导出订单'}</Button>
                </a>
                    <Grid transformData={this.transform} params={{id:BillInfo.id}} url="/api/settlement/settled/adjustInvoiceTaxList" columns={this.columnsPop} />     
                </SCModal>
            </div>
        )
    }
}

export default injectIntl(AdjustHis)